package com.nulldev.util.networking.npacket4.iprotocols.ncryptx.methods.newhope;

import java.util.Arrays;

public class NewHopePrivateKey {
	private RingElt s;
	private byte domain;

	public NewHopePrivateKey(RingElt sIn, byte dom) {
		s = new RingElt(sIn);
		if (dom == Constants.ORDINARY)
			s.ntt();
		domain = Constants.FOURIER;
	}

	public NewHopePrivateKey() {
		s = Sample.getSample();
		domain = Constants.ORDINARY;
	}

	public NewHopePrivateKey(byte[] inBytes) {
		domain = inBytes[0];
		s = new RingElt(Arrays.copyOfRange(inBytes, 1, inBytes.length));
	}

	public RingElt getS() {
		return s;
	}

	public void toFourierDomain() {
		if (domain == Constants.ORDINARY) {
			s.ntt();
			domain = Constants.FOURIER;
		}
	}

	public void fromFourierDomain() {
		if (domain == Constants.FOURIER) {
			s.nttInv();
			domain = Constants.ORDINARY;
		}
	}

	public byte[] serialize() {
		byte[] sba = s.toByteArray();
		byte[] ba = new byte[sba.length + 1];

		ba[0] = domain;
		System.arraycopy(sba, 0, ba, 1, sba.length);

		return ba;
	}
}